

#include "stdafx.h"
#include "CombatState_CoolDown.h"
#include "Combat/EvtCombat.h"
#include "Combat/CombatDefinition.h"
#include "Event/EvtImp.h"
#include "Combat/CombatSysImp.h"
#include "Entity/EntityIf.h"


enum
{
	time_CoolDown	=	500,			//	cool down time between to spell
};


CombatState_CoolDown::CombatState_CoolDown(void)

{
}

CombatState_CoolDown::~CombatState_CoolDown()
{
}

void
CombatState_CoolDown::enter()
{
	m_nTTL = time_CoolDown;
}

void
CombatState_CoolDown::leave()
{

}


bool 
CombatState_CoolDown::update(int nElapse)
{
	if (m_nTTL>0)
	{
		m_nTTL-=nElapse;
	}
	else
	{
		//
		//	transfer to ready status
		//
		m_nTTL = 0;
		m_wpCombat->setState(Combat::CBS_Ready);
	}
	return true;
}



void 
CombatState_CoolDown::onEvent(IEvt& evt)
{
	if (evt.getID()==EVT_CastStart)
	{
		if (!m_wpCombat->isCalculator())
		{
			m_wpCombat->onEvent_Cast(evt);
		}
		else
		{
			LOG_ERROR("Failed, calculator won't start a cast in cool down mode!\n");
		}
	}
	else if (evt.getID()==EVT_CastEnd)
	{
		LOG_ERROR_V("Failed to cast end in : %d !\n", m_wpCombat->getStateName());
	}
	else if (evt.getID()==EVT_CastResult)
	{
		m_wpCombat->onEvent_CastResult(evt);
	}
	else if (evt.getID()==EVT_CastPrep)
	{
		m_wpCombat->onEvent_CastPrep(evt);
	}
	else if (evt.getID()==EVT_TargetSelected)
	{
		m_wpCombat->onEvent_Target(evt);
	}
}


